package com.yjj.demo.thread.task;

import com.yjj.demo.thread.context.BeanContext;
import com.yjj.demo.thread.service.ThreadPoolService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 *
 * @author yangjiajia
 * @time 2022/3/20 22:40
 */
public class ThreadTask implements Runnable{

    private Logger logger = LoggerFactory.getLogger(ThreadTask.class);

    private int taskId;

    private ThreadPoolService threadPoolService;

    public ThreadTask(int taskId, ThreadPoolService threadPoolService) {
        this.taskId = taskId;
        this.threadPoolService = threadPoolService;
    }

    @Override
    public void run() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        logger.info("任务开始执行,taskId:{},time:{}", taskId, sdf.format(new Date()));

        taskId ++;

        //threadPoolService.nextTask(taskId);
        BeanContext.getBean(ThreadPoolService.class).nextTask(taskId);
    }

    public static void main(String[] args) {

        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(12);
        list.add(30);

        StringBuilder sb = new StringBuilder();
        for (Integer num : list) {
            sb.append(String.format("%02d", num));
        }

        long num = Long.parseLong(sb.toString());

        String str = String.valueOf(num);
        if (str.length() % 2 != 0) {
            str = "0" + str;
        }

        List<Integer> newList = new ArrayList<>();
        int idx = 0;
        while (true) {
            if (idx >= str.length()) {
                break;
            }
            String level = str.substring(idx, idx + 2);
            idx += 2;

            newList.add(Integer.parseInt(level));
        }

        for (Integer level : newList) {
            System.out.println("level:" + level);
        }
    }
}
